﻿using System;
using System.Collections;
using System.Collections.Generic;
using OpenTK;

namespace GingerGL.Graphics
{
    //------------------------------------------------------------//
    /// <summary>
    /// Scene
    /// </summary>
    public abstract class Scene : IEnumerable<IRenderable>
    {
        //--------------------------------------------------------//
        #region Variables
        private LinkedList<IRenderable> mRenderables;
        #endregion
        //--------------------------------------------------------//
        #region Properties
        /// <summary>
        /// Gets/Sets First IRenderable to be rendered
        /// </summary>
        public IRenderable FirstRenderable { get; set; }
        /// <summary>
        /// Gets/Sets Last IRenderable to be rendered
        /// </summary>
        public IRenderable LastRenderable { get; set; }
        /// <summary>
        /// Gets/Set Visibility of Entire Scene
        /// </summary>
        public bool Visible { get; set; }
        #endregion
        //--------------------------------------------------------//
        #region Constructor
        /// <summary>
        /// Initalizes a new instance of object
        /// </summary>
        public Scene()
        {
            this.Visible = true;
            this.FirstRenderable = null;
            this.LastRenderable = null;
            this.mRenderables = new LinkedList<IRenderable>();
        }
        #endregion
        //--------------------------------------------------------//
        #region Methods
        /// <summary>
        /// Add New Renderable object to scene
        /// </summary>
        public void Add(IRenderable renderable) { mRenderables.AddLast(renderable); }
        /// <summary>
        /// Remove a renderable item from scene and dispose of it
        /// </summary>
        public void Remove(IRenderable renderable)
        {
            if (mRenderables.Contains(renderable))
            {
                renderable.Dispose();
                mRenderables.Remove(renderable);
            }
        }
        /// <summary>
        /// Get Enumerator
        /// </summary>
        IEnumerator IEnumerable.GetEnumerator() { return mRenderables.GetEnumerator(); }
        /// <summary>
        /// Gets IRenderable Enumerator
        /// </summary>
        IEnumerator<IRenderable> IEnumerable<IRenderable>.GetEnumerator() { return mRenderables.GetEnumerator(); }
        /// <summary>
        /// Unload All Objects and Dispose of them
        /// </summary>
        public void UnloadAll()
        {
            foreach (IRenderable r in mRenderables)
                r.Dispose();
            mRenderables.Clear();
        }
        #endregion
        //--------------------------------------------------------//
    }
    //------------------------------------------------------------//
}
